﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>新增工作报告</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <link href="../Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <link href="../JS/Date/FT_Date.min.css" rel="stylesheet" />
    <script src="../JS/layer/layer.m.js"></script>
    <style type="text/css">
        .ui-select {
            border: none;
            border: 0;
            background-color: #fff;
            appearance: none;
            -moz-appearance: none; /* Firefox */
            -webkit-appearance: none; /* Safari 和 Chrome */
        }

        .ms-controller, [ms-controller] {
            display: none;
        }
        .ui-form-item .wspan {
            width: 100%;
            display: -webkit-box;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            -webkit-appearance: none;
            border: 0;
            background: 0 0;
            padding-left: 95px;
        }
        .ui-form-item .wspan img {
            width: 50px;
            height: 50px;
            padding-right: 3px;
        }

        .sctp {
            color: #18b4ed;
            right: 4px;
            top: -5px;
            z-index: 9;
            width: 20px;
            height: 20px;
            background: #fff;
            border-radius: 13px;
            line-height: 20px;
            text-indent: -3px;
            position: absolute;
            font-size: 25px;
        }

        .imgxl {
            position: relative;
            float: left;
            padding-top: 0;
            height: 50px;
            width: 50px;
            padding-right: 10px;
            margin-left: 0px;
            margin-bottom: 5px;
        }

        .tpxs {
            height: 50px;
            width: 50px;
            position: absolute;
            top: 0;
            left: 0;
            z-index: 1;
            background-repeat: no-repeat;
            -webkit-background-size: cover;
        }
    </style>
</head>
<body ms-controller="rbmodel">
    <header ms-if="isbj" class="ui-header ui-header-stable ui-border-b">
        <i class="ui-icon-return" onclick="back()"></i>
        <h1>工作报告修改</h1>
    </header>
    <div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
        <button class="ui-btn-lg" onclick="back()">
            取消
        </button>
        <button class="ui-btn-lg ui-btn-primary" id="save" ms-click="savedata()">
            新增报告
        </button>
    </div>
    <section class="ui-container">

        <div class="ui-form">
            <div class="ui-form-item ui-border-b ">
                <label>
                    类型
                </label>
                <div class="ui-select ui-border-b">
                    <select ms-duplex="ctData.LeiBie"></select>
                </div>
            </div>
            <div class="ui-form-item ui-border-b">
                <label>
                    时间
                </label>
                <div class="ui-select ui-border-b">
                    <input type="text" placeholder="0001-01-01" id="appSDate" ms-duplex="ctData.RBDate" style="padding-left:0" />
                </div>
            </div>
            <div class="ui-form-item ui-border-b ui-form-item-textarea" style="height:auto;">
                <label>
                    内容
                </label>
                <textarea placeholder="请输入内容" style="height:80px;" class="chackTextarea-area" ms-duplex="ctData.RBContent"></textarea>
                <!--<div class="ui-txt-muted ui-whitespace" style="padding-left: 95px;text-align:justify" id="hdjj" ms-click="bjk()">请输入内容</div>-->
                <!--<input type="text" placeholder="请输入内容" ms-duplex="ctData.RBContent" />-->
            </div>
            <div class="ui-form-item ui-border-b ui-form-item-textarea" style="height:auto;">
                <label>
                    完成情况
                </label>
                <textarea placeholder="请输入完成情况" style="height:80px;" class="chackTextarea-area" ms-duplex="ctData.RBWCQK"></textarea>
                <!--<input type="text" placeholder="请输入完成情况" ms-duplex="ctData.RBWCQK" />-->
                <!-- <div class="ui-txt-muted ui-whitespace" style="padding-left: 95px;text-align:justify" id="wcqk" ms-click="wcbjk()">请输入完成情况</div>-->
            </div>
            <div class="ui-form-item ui-border-b" style="height:auto;min-height:44px">
                <label>
                    上传图片
                </label>

                <div class="wspan" style="padding-top: 5px; height: auto;display:block">
                    <ul id="imglist">
                        <span ms-repeat-fl="ftData">
                            <li class="imgxl tpli" ms-attr-itemid="{{fl.ID}}" ms-if="MobileCom.xstp(fl.FileExtendName)">
                                <span ms-css-background-image="url({{imgurl+'image/'+fl.FileMD5}})" class="tpxs"></span>
                                <i class="ui-icon-close-progress sctp" ms-click="sctp(fl)"></i>
                            </li>
                        </span>
                        <span ms-repeat-fls="ftData">
                            <li class="imgxl tpli" ms-attr-itemid="{{fls.ID}}" ms-if="!MobileCom.xstp(fls.FileExtendName)">
                                <span ms-css-background-image="url({{'/MobileView/Images/qywd/'+fls.FileExtendName+'.png'}})" class="tpxs"></span>
                                <i class="ui-icon-close-progress sctp" ms-click="sctp(fls)"></i>
                            </li>
                        </span>
                        <li class="imgxl scli"><img id="add_pit" src="../Images/icon-add.png" /></li>
                    </ul>
                    <div style="clear:both"></div>
                </div>
            </div>

        </div>
    </section>
    <!--<script src="http://cdnjs.gtimg.com/cdnjs/libs/jquery/2.1.1/jquery.min.js"></script>-->
    <!--<script src="../JS/Jquery2.1.js"></script>
    <script src="../JS/Date/FT_Date.min.js"></script>-->

    <script src="../JS/zepto.min.js"></script>
    <script src="../Frozenui1.3/js/frozen.js"></script>
    <script src="../JS/avalon.mobile.min.js"></script>
    <script src="../JS/mobiscroll.zepto.js"></script>
    <script src="../JS/mobiscroll.core.js"></script>
    <script src="../JS/mobiscroll.scroller.js"></script>
    <script src="../JS/mobiscroll.datetime.js"></script>
    <!--<script src="../JS/mobiscroll.select.js"></script>-->
    <script src="../JS/mobiscroll.i18n.zh.js"></script>
    <script src="../JS/jquery.autoTextarea.js"></script>
    <script>
        //var jq = $.noConflict();
        var currYear = (new Date()).getFullYear();
        var opt = {
            date: { preset: 'date' },
            defaultopi: {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                lang: 'zh',
                startYear: currYear - 5, //开始年份
                endYear: currYear + 5, //结束年份
                onSelect: function (valueText, inst) {
                    model.ctData.RBDate = valueText;
                }
            }
        };
        function fun(str) {
            $("#appSDate").scroller($.extend(opt['date'], opt['defaultopi'])).scroller('setDate', str, true);
        }

        $(".chackTextarea-area").autoTextarea({
            maxHeight: 220,
            minHeight: 80
        });

    </script>

    <!-- <script src="../JS/wxconfig.js"></script>-->
    <script src="../JS/MobileCom.js?v=1.1"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script>
        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
            //隐藏右上角按钮
            WeixinJSBridge.call('hideOptionMenu');
        });

        var strId = MobileCom.getQueryString("ID");

        //if (MobileCom.getCookie("szhlcode") == null) {
        //    MobileCom.setCookie("szhlcode", "3525c307-ada6-4588-bf96-3eee2352688a", 7);
        //}

        var width = 0;
        var model = avalon.define({
            $id: "rbmodel",
            isbj: "",
            ctData: { "LeiBie": "", "RBDate": "", "RBContent": "", "RBWCQK": "", "Files": "" },
            ftData: [],
            sctp: function (scel) {
                model.ftData.remove(scel);
            },
            imgurl: "",
            wximg: "",
            savedata: function () {
                if (model.ctData.LeiBie == "") {
                    $.tips({
                        content: "请选择类别",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.RBDate == "") {
                    $.tips({
                        content: "请输入时间",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.RBContent == "") {
                    $.tips({
                        content: "请输入内容",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                //if (model.ctData.RBWCQK == "") {
                //    $.tips({
                //        content: "请输入完成情况",
                //        stayTime: 2000,
                //        type: "warn"
                //    })
                //    return;
                //}
                var lg = $.loading({
                    content: '保存中...',
                })
                model.ctData.Files = "";
                $("#imglist .tpli").each(function () {
                    if ($(this).hasClass("wximg")) { //微信上传未处理的图片
                        if (model.wximg) {
                            model.wximg += ",";
                        }
                        model.wximg += $(this).attr("itemid");

                    } else {
                        if (model.ctData.Files) {
                            model.ctData.Files = model.ctData.Files + ',' + $(this).attr("itemid");
                        }
                        else {
                            model.ctData.Files = $(this).attr("itemid");
                        }
                    }

                })


                //model.ctData.Files = imgurl;
                $.post("/API/WXAPI.ashx?Action=ADDGZRZ&r=" + Math.random(), { "P1": JSON.stringify(model.ctData.$model), "P2": model.wximg }, function (data) {
                    lg.hide();
                    var data = $.parseJSON(data);
                    if (data.ErrorMsg == "") {
                        $("button").hide();
                        var el = $.tips({
                            content: "保存成功！",
                            stayTime: 2000,
                            type: "success"
                        })
                        el.on("tips:hide", function () {
                            //window.location.reload();
                            if (model.isbj == "") {
                                window.location.replace(location.href);
                            }
                            else {
                                window.location.replace("UI_GZRB_LIST.html?r=" + Math.random());
                            }
                        })
                    }
                    else {
                        $.tips({
                            content: "保存失败，原因：" + data.ErrorMsg,
                            stayTime: 2000,
                            type: "warn"
                        })
                    }
                })
            },
            bjk: function () {

                var tc = layer.open({
                    type: 1,
                    //content:$("#bmxx").html(),
                    //title: "活动简介",
                    content: '<div class="ui-form-item ui-form-item-textarea ui-border-b" style="width:' + (width - 76) + 'px;height:200px"><textarea id="hdjjbjk" style="padding-left: 0;height:170px;border: 1px solid #e0e0e0;" placeholder="请输入内容">' + model.ctData.RBContent + '</textarea></div>',
                    btn: ['确认', '取消'],
                    shadeClose: false,
                    yes: function () {
                        model.ctData.RBContent = $("#hdjjbjk").val();
                        if ($("#hdjjbjk").val() != "") {
                            $("#hdjj").removeClass("ui-txt-muted");
                            $("#hdjj").html($("#hdjjbjk").val());
                        }
                        else {
                            $("#hdjj").addClass("ui-txt-muted");
                            $("#hdjj").html("请输入内容");
                        }

                        layer.close(tc);

                    }, no: function () {
                    }
                })
                $("#hdjjbjk").focus();
            },
            wcbjk: function () {
                var tc = layer.open({
                    type: 1,
                    //content:$("#bmxx").html(),
                    //title: "活动简介",
                    content: '<div class="ui-form-item ui-form-item-textarea ui-border-b" style="width:' + (width - 76) + 'px;height:200px"><textarea id="hdjjbjk" style="padding-left: 0;height:170px;border: 1px solid #e0e0e0;" placeholder="请输入完成情况">' + model.ctData.RBWCQK + '</textarea></div>',
                    btn: ['确认', '取消'],
                    shadeClose: false,
                    yes: function () {
                        model.ctData.RBWCQK = $("#hdjjbjk").val();
                        if ($("#hdjjbjk").val() != "") {
                            $("#wcqk").removeClass("ui-txt-muted");
                            $("#wcqk").html($("#hdjjbjk").val());
                        }
                        else {
                            $("#wcqk").addClass("ui-txt-muted");
                            $("#wcqk").html("请输入完成情况");
                        }

                        layer.close(tc);

                    }, no: function () {
                    }
                })
                $("#hdjjbjk").focus();
            }

        });

        avalon.ready(function () {
            if (strId) {
                model.isbj = "Y";
                $("#save").text("保存");
                $("title").text("修改工作报告");
            } else {
                fun(new Date());
                model.ctData.RBDate = $("#appSDate").val();
            }
            width = document.documentElement.clientWidth;
            var lg = $.loading({
                content: '加载中...',
            })
            $.post("/API/WXAPI.ashx?Action=GETCOLUMNLIST&r=" + Math.random(), { "P1": "7" }, function (data) {
                if (!strId) {
                    lg.hide();
                }
                var data = $.parseJSON(data);
                if (data.ErrorMsg == "") {
                    $("select").empty();
                    for (var i = 0; i < data.Result.length; i++) {
                        $("select").append('<option value="' + data.Result[i].TypeNO + '">' + data.Result[i].TypeNO + '</option>');
                        if (i == 0) {
                            model.ctData.LeiBie = data.Result[i].TypeNO;
                        }
                    }
                    if (strId) {

                        $.getJSON('/API/WXAPI.ashx?Action=GETGZRZMODEL&r=' + Math.random(), { P1: strId }, function (resultData) {
                            lg.hide();
                            if (resultData.ErrorMsg == "") {
                                model.ctData = resultData.Result;
                                model.ftData = resultData.Result2;

                                if (model.ctData.RBContent != "" && model.ctData.RBContent != null) {
                                    $("#hdjj").removeClass("ui-txt-muted");
                                    $("#hdjj").html(model.ctData.RBContent);
                                }
                                if (model.ctData.RBWCQK != "" && model.ctData.RBWCQK != null) {
                                    $("#wcqk").removeClass("ui-txt-muted");
                                    $("#wcqk").html(model.ctData.RBWCQK);
                                }

                                var arr1 = model.ctData.RBDate.substring(0, 10).split("-");
                                var time1 = new Date(arr1[0], arr1[1] - 1, arr1[2]);

                                fun(time1);
                                model.ctData.RBDate = model.ctData.RBDate.substring(0, 10)

                            }
                        })
                    }
                    else {
                        lg.hide();
                    }
                }
                else {
                    $.tips({
                        content: "类型加载失败，原因：" + data.ErrorMsg,
                        stayTime: 2000,
                        type: "warn"
                    })
                }
            })

            MobileCom.uploadimg();

            $.post("/API/SZHLAPI.ashx?Action=GetUserInfo&r=" + Math.random(), {}, function (data) {

                var data = $.parseJSON(data);
                if (data.ErrorMsg == "") {
                    if (data.Result.QYinfo.FileServerUrl) {
                        var str = data.Result.QYinfo.FileServerUrl;
                        if (str.substr(str.length - 1, 1) != "/") {
                            str = str + "/";
                        }
                        model.imgurl = str;
                    }
                }
            })
        })
        function back() {
            window.location.replace("UI_GZRB_LIST.html?r=" + Math.random());
        }
    </script>

</body>

</html>
